package cc.laop.support.realm;

import cc.laop.utils.PasswordDigestUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;


/**
 * 通过md5加密后的密码与系统加密后的密码对比校验，内容一致就返回true,否则返回false;
 *
 * @author Administrator
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authcToken,
                                      AuthenticationInfo info) {
        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
        String dbPassword = String.valueOf(getCredentials(info));
        String password = String.valueOf(token.getPassword());
        return PasswordDigestUtil.checkMd5Digest(password, dbPassword);
    }

}
